package cn.antblog.multi.datasource.util;

import cn.antblog.multi.datasource.constant.Const;

/**
 * @author yangjy
 * @version 1.0
 * @description: 创建数据源key的切换工具
 * 主要用于设置当前线程下数据源切换时的数据源唯一标识key，以便获取指定的数据源
 * @date 2022/11/22 11:12
 */
public class DynamicDataSourceHolder {
    private static final ThreadLocal<String> DATA_SOURCE_THEAD_LOCAL
            = ThreadLocal.withInitial(()-> Const.DEFAULT);

    public static String getDataSource(){
        return DATA_SOURCE_THEAD_LOCAL.get();
    }

    public static void setDataSource(String dataSource) {
        DATA_SOURCE_THEAD_LOCAL.set(dataSource);
    }

    public static void remove() {
        DATA_SOURCE_THEAD_LOCAL.remove();
    }

}
